package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.arch.core.internal.SafeIterableMap;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class RateListActivity extends AppCompatActivity {
    private Handler handler;
    private ProgressBar bar;
    private String logDate = "";
    private final String DATE_SP_KEY = "lastRateDateStr";


    //body > div > div.BOC_main > div.publish > div:nth-child(3) > table > tbody > tr:nth-child(2) > td:nth-child(1)
    //body > div > div.BOC_main > div.publish > div:nth-child(3) > table > tbody > tr:nth-child(2) > td:nth-child(4)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      //  super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_rate_list);


        SharedPreferences sp = getSharedPreferences("myrate", Context.MODE_PRIVATE);
        logDate = sp.getString(DATE_SP_KEY, "");
        Log.i("List","lastRateDateStr=" + logDate);
        setContentView(R.layout.activity_rate_list);
        ListView mylist = findViewById(R.id.mylistview);
        bar =findViewById(R.id.progressBar7);
        mylist.setEmptyView(bar);

        String data[] = {"one","two","three"};
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data);
        mylist.setAdapter(adapter);

        handler = new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                if(msg.what==5){
                    List<String> list = (List<String>) msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(RateListActivity.this, android.R.layout.simple_list_item_1,list);
                    mylist.setAdapter(adapter);
                    bar.setVisibility(View.GONE);
                }
                super.handleMessage(msg);
            }
        };
        MyTask myTask = new MyTask();
        myTask.setHandler(handler);

        Thread t = new Thread(myTask);
        t.start();

    }


}